#!/usr/bin/env node

const Koa = require('koa'),
      Router = require('koa-router'),
      bodyparser = require('koa-bodyparser')

const app = new Koa(),
      router = new Router();

app.use(bodyparser())

app.use((ctx, next) => {
    console.log(`${ctx.method} ${ctx.path}`)
    next()
})

router.prefix('/api/authors')

router.get('/', async(ctx) => {
  const {page, limit} = ctx.query
  console.log(ctx.request.headers)
  ctx.body = `分页查询漫画书作者, page=${page}&limit=${limit}`
})

router.get('/:authorName', async(ctx) => {
  const {authorName} = ctx.params
  ctx.body = `按名称查询漫画书作者,authorName=${authorName}`
})

router.post('/', async(ctx) => {
  const {authorName,age} = ctx.request.body
  ctx.body = `添加漫画书作者,authorName=${authorName}&age=${age}`
})

router.put('/:id', async(ctx) => {
  ctx.body = '修改漫画书作者'
})

router.delete('/:id', async(ctx) => {
  ctx.body = '删除漫画书作者'
})

app.use(router.routes());

app.listen(3000)

